package com.prim.threadcoreknowledge.stopthread;

/**
 * 错误的停止方法用stop停止线程，
 * 会导致线程运行一半，突然停止，没办法完成一个基本单位的操作
 * 会造成脏数据
 */
public class StopThread implements Runnable {
    @Override
    public void run() {
        //模拟指挥军队：一共有5个连队，每个连队100人，以连队为单位，发放武器弹药
        //叫到号的士兵 领取装备
        for (int i = 0; i < 5; i++) {
            System.out.println("连队" + i + "开始领取武器");
            for (int j = 0; j < 10; j++) {
                System.out.println(j);
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("连队" + i + "领取完毕");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new StopThread());
        thread.start();
        //假设1s后，立马去前线
        Thread.sleep(1000);
        //错误的停止方法导致连队的士兵没有领取到装备
        thread.stop();
    }
}
